package com.hkccommunity.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateConversionUtil {

    private String dateStr;

    public static String dateConversion(String dateString){
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(dateString, pattern);
        LocalDateTime now = LocalDateTime.now();

        //日期转换
        if(dateTime.getYear() == now.getYear() && dateTime.getMonth() == now.getMonth()){
            if(dateTime.getDayOfMonth() == now.getDayOfMonth()){
                dateString = "今天 " + dateString.substring(10,16);
                return dateString;
            }else if (dateTime.getDayOfMonth() == now.getDayOfMonth()-1){
                dateString = "昨天 " + dateString.substring(10,16);
                return dateString;
            }
        }


        return dateString.substring(0,dateString.length()-3);
    }


    public static String dateToString(){
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();

        String format = now.format(pattern);
        return format;


    }
}
